﻿using adb;
using Masuit.Tools;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.EntityFrameworkCore;
using NPOI.OpenXmlFormats.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using utils;

namespace Notication.AppCode
{
    /// <summary>
    ///  计算统计
    /// </summary>
    public static class StatisticsRun
    {
        public static DateTime t = DateTime.Now;

        private static adb.dbBase db = new adb.dbBase();
        static StatisticsRun() {
            th.Start();
            //  th2.Start();
        }

        private static Thread th = new Thread(async () => {
            while (true)
            {
                try
                {
                    DateTime t = DateTime.Now.Minute < 30 ? DateTime.Parse($"{DateTime.Now:yyyy-MM-dd HH:00:00}") : DateTime.Parse($"{DateTime.Now:yyyy-MM-dd HH:30:00}");
                    await StatisticsUtils.Power_new(t);
                    await StatisticsUtils.Power_new(t.AddMinutes(-30));
                    Thread.Sleep(1000 * 10);
                }
                catch (Exception ex)
                {
                    writeExceptionLogUtil.writeLogException(ex,"/root/logs","Notication");
                    Console.WriteLine("统计数据出错:" + ex.Message+ex.StackTrace);
                }
            }
        });

    }
}
